import datetime
from playhouse.signals import pre_save, Model
from flask_pw.models import Model as Model_
from ..models.account import Account
from ..models.order import Order
from peewee import *
from ..database import database, ModelMixin


class AccountHistory(database.Model, ModelMixin):
    id = PrimaryKeyField(primary_key=True)
    account = ForeignKeyField(Account)
    direction = CharField(max_length=10, default='debit', help_text='借贷方向 debit 借方  credit  贷方')
    amount = DecimalField(db_column='amount', decimal_places=4, help_text='amount')
    remark = CharField(max_length=200, db_column='remark', help_text='描述信息')
    type = CharField(max_length=20, help_text='账户历史类型')
    order = ForeignKeyField(Order)
    settle_time = DateTimeField()
    created_at = DateTimeField()
    updated_at = DateTimeField()
    settled_at = DateTimeField(null=True)
    status = CharField(max_length=20, default='done')

    CREDIT_DIRECTION = 'credit'

    DEBIT_DIRECTION = 'debit'
